ch = int(input())
a = ch // 1000
b = (ch // 100) % 10
c = (ch // 10) % 10
d = ch % 10
sp = []
chislo = int( str(a) + str(b) + str(c) + str(d))
k = 0
for i in range(1, chislo + 1):
    if chislo % i == 0:
        k += 1
if k == 2:
    sp.append(chislo)
if a != 0 and a != 1:
    chislo = a
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
             k += 1
if k == 2:
    sp.append(chislo)

if b != 0 and b != 1:
    chislo = b
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1
    if k == 2:
        sp.append(chislo)

if c != 0 and c != 1:
    chislo = c
    k = 0
    for i in range(1, chislo + 1):
            if chislo % i == 0:
                    k += 1
    if k == 2:
        sp.append(chislo)

if d != 0 and d != 1:
    chislo = d
    k = 0
    for i in range(1, chislo + 1):
            if chislo % i == 0:
                k += 1
    if k == 2:
        sp.append(chislo)
chislo = int( str(a) + str(b) )
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1

if k == 2:
    sp.append(chislo)

chislo = int(str(a) + str(c))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1

if k == 2:
    sp.append(chislo)
chislo = int(str(b) + str(c))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1

if k == 2:
    sp.append(chislo)
chislo = int(str(b) + str(d))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1

if k == 2:
    sp.append(chislo)
chislo = int(str(c) + str(d))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1

if k == 2:
    sp.append(chislo)
chislo = int( str(a) + str(b) + str(c))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1

    if k == 2:
        sp.append(chislo)

chislo = int(str(b) + str(c) + str(d))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
                k += 1
    if k == 2:
        sp.append(chislo)
chislo = int(str(a) + str(b) + str(d))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1
    if k == 2:
            sp.append(chislo)
chislo = int(str(a) + str(c) + str(d))
if chislo != 0 and chislo != 1:
    k = 0
    for i in range(1, chislo + 1):
        if chislo % i == 0:
            k += 1
    if k == 2:
            sp.append(chislo)

if len(sp) == 0:
    print(0)
else:
    print(max(sp))






